x = 3
y = 5
z = 4

import sys

stack = [(0, 0)]
seen = set()
while stack:
    remain_x, remain_y = stack.pop()
    if remain_x == z or remain_y == z or remain_x + remain_y == z:
        print('true')
        sys.exit(0)
    if (remain_x, remain_y) in seen:
        continue
    seen.add((remain_x, remain_y))
    # 把 X 壶灌满。
    stack.append((x, remain_y))
    # 把 Y 壶灌满。
    stack.append((remain_x, y))
    # 把 X 壶倒空。
    stack.append((0, remain_y))
    # 把 Y 壶倒空。
    stack.append((remain_x, 0))
    # 把 X 壶的水灌进 Y 壶，直至灌满或倒空。
    stack.append((remain_x - min(remain_x, y - remain_y), remain_y + min(remain_x, y - remain_y)))
    # 把 Y 壶的水灌进 X 壶，直至灌满或倒空。
    stack.append((remain_x + min(remain_y, x - remain_x), remain_y - min(remain_y, x - remain_x)))
print("false")
